//
//  TermAndCondition.m
//  KutulusLaw
//
//  Created by phuc phuc on 12/10/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "TermAndCondition.h"
#import "FrontViewController.h"
#import "RearViewController.h"
#import "KurtulusLawController.h"
#import "RTLabel.h"

@interface TermAndCondition()
{
	BOOL _checkTerm;
}
@end

@implementation TermAndCondition
@synthesize textViewTerm;
@synthesize lb1;
@synthesize lb2;
@synthesize scrollView;
@synthesize btnCheckTerm;
@synthesize btnMyProfile;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
	self.btnMyProfile.alpha = 0.4;
	[self.btnMyProfile setTitle:NSLocalizedString(@"My Profile", nil) forState:UIControlStateNormal];
	self.lb1.text = NSLocalizedString(@"Terms and Conditions", nil);
	self.lb2.text = NSLocalizedString(@"I have Read and Understood the Terms and Conditions", nil);;
	NSString *sample_text = NSLocalizedString(@"Term And Conditions Content", nil);

	RTLabel *lbTerm = [[RTLabel alloc] initWithFrame:CGRectMake(10, 100, 300, 60)];
	
	[lbTerm setText: sample_text];
	CGRect frame = [lbTerm frame];
	frame.size = [lbTerm optimumSize];
	[lbTerm setFrame:frame];
	[self.scrollView addSubview:lbTerm];
	[self.scrollView setContentSize:CGSizeMake(320, 100 + frame.size.height)];
}

- (void)viewDidUnload
{
    [self setBtnCheckTerm:nil];
	[self setBtnMyProfile:nil];
	[self setTextViewTerm:nil];
    [self setLb1:nil];
    [self setLb2:nil];
	[self setScrollView:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)touchCheckbox:(id)sender {
	NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
	if (_checkTerm) {
		self.btnMyProfile.alpha = 0.4;
		[self.btnCheckTerm setImage:[UIImage imageNamed:@"check-box-off-31x32"] forState:UIControlStateNormal];
		self.btnMyProfile.userInteractionEnabled = NO;
		[userDefault setObject: [NSNumber numberWithInt:0] forKey:@"checkterm"];
		_checkTerm = NO;
	}
	else
	{
		self.btnMyProfile.alpha = 1;
		[self.btnCheckTerm setImage:[UIImage imageNamed:@"check-box-on-31x32"] forState:UIControlStateNormal];
		self.btnMyProfile.userInteractionEnabled = YES;
		[userDefault setObject: [NSNumber numberWithInt:1] forKey:@"checkterm"];
		_checkTerm = YES;
	}
	
}

- (IBAction)touchMyProfile:(id)sender {
	    FrontViewController *frontViewController = [[FrontViewController alloc] init];
		RearViewController *rearViewController = [[RearViewController alloc] init];
		
		UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
		
		KurtulusLawController *revealController = [[KurtulusLawController alloc] initWithFrontViewController:navigationController rearViewController:rearViewController];
		UIViewController *view = revealController;
	    
	    [view setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
	    [self presentModalViewController:view animated:YES];
	    [revealController revealToggle:nil];
	
}

@end
